#include "../comm.h"
class Solution {
public:
    long long maxScore(vector<int>& nums, int x) {
        long long ans = nums[0];
        // 锁定前面奇数最大和偶数最大的内容
        int oddi, si;
        if(nums[0] % 2) oddi = 0, si = -1;
        else oddi = -1, si = 0;
        vector<long long> dp(nums.size(), -0x3f3f3f3f);
        dp[0] = nums[0];
        for(int i = 1; i < nums.size(); ++i)
        {
            bool odd = nums[i]  % 2;
            if(~oddi) dp[i] =  dp[oddi] + nums[i] - (!odd * x);
            if(~si) dp[i] = max(dp[i], dp[si] + nums[i] - (odd * x));
            if(odd && (oddi == -1 || dp[i] > dp[oddi])) oddi = i;
            if(!odd && (si == -1 || dp[i] > dp[si])) si = i;
            ans = max(ans, dp[i]);
        }
        return ans;
    }
};